package com.masita.ventanas;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

public class ModeloTabla extends AbstractTableModel {

	private String[] columnNames = null;
	private Object[][] data = null; 
	
	public int getColumnCount() {
		return columnNames.length;
	}

	public int getRowCount() {
		return data.length;
	}

	public String getColumnName(int col) {
		return columnNames[col].toString();
	}

	public Object getValueAt(int row, int col) {
		return data[row][col];
	}

	public Class getColumnClass(int c) {
		return getValueAt(0, c).getClass();
	}

	public boolean isCellEditable(int row, int col){
		if( col == 0 )
			return true;
		return false;
	}

	public void setValueAt(Object value, int row, int col) {
		data[row][col] = value;
		fireTableCellUpdated(row, col);
	}
	
	// CONSTRUCTOR ****************************************
	public ModeloTabla(int f, int c){
		this.columnNames = new String[c];
		this.data = new Object[f][c];
	}
	
	// ****************************************************
	public void cargarColumnas(Vector col){
		for( int i=0; i<col.size(); i++)
			this.columnNames[i] = new String(col.elementAt(i).toString());
	}

	public boolean cargarDatos(Vector datos){
		if( this.data != null ){

			for(int i=0; i<datos.size(); i++){
				Vector fila = (Vector)datos.elementAt(i);
				for(int j=0; j<fila.size(); j++){
					this.setValueAt(fila.elementAt(j),i,j);
				}
			}
			return true;
		}
		return false;
	}
	
}
